import initConfig from "./init";
const hasPermission = {
    install (Vue, options) {
        Vue.directive("has", {
            inserted: (el, binding, vnode)=>{
                filterGlobalPermission(el, binding, vnode);
            }
        });
    }
};
/**
 * 全局权限控制
 */
export const filterGlobalPermission = (el, binding, vnode) => {
    console.log("待判定的权限：",binding.value)
    let permissionList = JSON.parse(localStorage.getItem("express_admin_auth") || "[]");
    // 特殊权限用户判定
    let uid = parseInt(localStorage.getItem("express_admin_id"))
    if(uid <= 0 || !initConfig.config.loginf.privilege.includes(uid)){
        if (!permissionList.includes(binding.value)) {
            el.parentNode.removeChild(el);
        } else if (uid <= 0){
            el.parentNode.removeChild(el);
        }
    }
}
export default hasPermission;
